package com.bestcem.xm.ticket.entity.mongo;

import com.bestcem.xm.ticket.constant.ColumnConstant;
import com.bestcem.xm.ticket.enums.TemplateTypeEnum;
import com.bestcem.xm.ticket.enums.TemplateUsedEnum;
import com.bestcem.xm.ticket.enums.TicketTemplateFieldUpdatedEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.io.Serializable;
import java.util.List;

/**
 * 新增需求模板
 *
 * @author xuan.yang <xuan.yang@idiaoyan.com>
 * @version v2.3
 * @date 2021/9/1 15:54
 */
@ToString(callSuper = true)
@Getter
@Setter
public class TicketTemplateV2 extends BaseEntity {
    private static final long serialVersionUID = -7253778583948098510L;

    /**
     * orgId
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.ORG_ID)
    private String orgId;

    /**
     * ticketConfigId
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.TICKET_CONFIG_ID)
    private String ticketConfigId;

    /**
     * name
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.NAME)
    private String name;
    /**
     * type
     * 模板类型1-详情，2-处理模板 {@link TemplateTypeEnum}
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.TYPE)
    private Integer type;

    /**
     * seq 默认模板是0，在创建模板的时候需要穿进来0，不传默认普通模板1
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.SEQUENCE)
    private Integer seq = 1;


    private String creator;

    /**
     * 模板字段列表，长度不限
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.FIELD_LIST)
    private List<FieldInfo> fieldList;

    /**
     * 是否sample
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.SAMPLE)
    private Boolean sample;

    /**
     * 是否被使用，
     * 1-被使用，2-未被使用
     * 这个字段，新增的时候不会被传过来，也不会被修改，仅用作后台查询时的返回 {@link TemplateUsedEnum}
     */
    @JsonProperty(value = ColumnConstant.TicketTemplateV2.USE)
    private Integer used;

    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class FieldInfo implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        /**
         * name
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.NAME)
        private String name;
        /**
         * type
         * text--1单行文本； multiLine--2 多行文本；
         * select---3单选； cascadeSelect--4 级联选择
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.TYPE)
        private Integer type;
        /**
         * require
         * 默认false
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.REQUIRED)
        private Boolean required = Boolean.FALSE;

        /**
         * filed
         * 字段key
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.FIELD)
        private String field;
        /**
         * value
         * 单行或者多行的值
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.VALUE)
        private String value;

        /**
         * singleSelectValue
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.SINGLE_SELECT)
        private SingleSelect singleSelect;

        /**
         * CascadeValue
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.FieldInfo.CASCADE_LIST)
        private List<Cascade> cascadeList;

        /**
         * 是否允许修改该字段，默认1 {@link TicketTemplateFieldUpdatedEnum}
         */
        private Integer isUpdate = TicketTemplateFieldUpdatedEnum.TEMPLATE_IS_UPDATE.getIndex();
    }


    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class SingleSelect implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        /**
         * options
         * 当source为1的时候存在数值
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.SingleSelectValue.OPTION_LIST)
        private List<Option> optionList;

        /**
         * content，该字段指的是source来源对应的汉字描述，该字段应该不会被使用
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.SingleSelectValue.CONTENT)
        private String content;
        /**
         * source
         * 1-自定义数据，2-系统问卷数据 3-系统联系人数据
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.SingleSelectValue.SOURCE)
        private Integer source;


        @NoArgsConstructor
        @AllArgsConstructor
        @Data
        public static class Option implements Serializable {
            private static final long serialVersionUID = 2808726620840986656L;
            /**
             * 选项内容
             */
            @JsonProperty(value = ColumnConstant.TicketTemplateV2.SingleSelectValue.Option.FIELD)
            private String field;
            /**
             * 与选项内容对应的前端标识，生成规则：从0开始自增
             */
            @JsonProperty(value = ColumnConstant.TicketTemplateV2.SingleSelectValue.Option.VALUE)
            private Integer value;


        }

    }

    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class Cascade implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;
        /**
         * 层级列表
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.Cascade.OPTION_LIST)
        private List<Option> optionList;
        /**
         * 级联层级，默认从1开始 {}
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.Cascade.LEVEL)
        private Integer level;


    }


    @NoArgsConstructor
    @AllArgsConstructor
    @Data
    public static class Option implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        /**
         * id
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.Option.ID)
        private String id;
        /**
         * pid
         * 父id，存在多级关联
         * 父id的pid为0
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.Option.PID)
        private String pid;
        /**
         * value
         */
        @JsonProperty(value = ColumnConstant.TicketTemplateV2.Option.VALUE)
        private String value;

    }
}
